package cn.venturesights.saber.mars.service;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.concurrent.FutureTask;

@Service
public class PostConstructService {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    ThreadPoolTaskExecutor executor;

    @PostConstruct
    public void taskAfterStartup() {
        logger.info("run task after startup");
        asyncTask();
    }

    public void asyncTask() {
        FutureTask<String> task = new FutureTask<>(
                () -> {
                    logger.info("it's a async task");
                    return "done";
                }
        );

        executor.execute(task);
    }

}
